package com.example.mynewsapp.util

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteDatabase.CursorFactory
import android.database.sqlite.SQLiteOpenHelper
//带全部参数的构造函数，此构造函数必不可少
class DatabaseHelper  (context: Context?, name: String?, factory: CursorFactory?, version: Int) :
    SQLiteOpenHelper(context, name, factory, version) {
    override fun onCreate(db: SQLiteDatabase) {
        //创建数据库sql语句 并 执行
        val sql1 = "create table history(newsImage text, newsUpdate varchar(20), newsCountry varchar(200), newsTitle text, newsDate varchar(50), newsUrl text, newsLike varchar(5))"
        val sql2 = "create table favorite(newsImage text, newsUpdate varchar(20), newsCountry varchar(200), newsTitle text, newsDate varchar(50), newsUrl text, newsLike varchar(5))"
        val sql3 = "create table videoHistory(videoImage text, videoTitle text, videoDesc text, videoProvider text, videoDate varchar(20), videoUrl text, videoLike varchar(5))"
        val sql4 = "create table videoFavorite(videoImage text, videoTitle text, videoDesc text, videoProvider text, videoDate varchar(20), videoUrl text, videoLike varchar(5))"
        db.execSQL(sql1)
        db.execSQL(sql2)
        db.execSQL(sql3)
        db.execSQL(sql4)
    }

    override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {}
}